﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for HoTroTrucTuyenDAO
/// </summary>
public class HoTroTrucTuyenDAO
{
    DataProvider provider;
	public HoTroTrucTuyenDAO()
	{
        provider = new DataProvider();
	}

    public List<HoTroTrucTuyen> HienThiHoTroTrucTuyen()
    {
        List<HoTroTrucTuyen> list = new List<HoTroTrucTuyen>();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_HienThi", provider.Conn);
            cmd.Parameters.Add("@TenBang", SqlDbType.VarChar).Value = "HoTroTrucTuyen";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection.Open();

            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            adapter.SelectCommand = cmd;
            adapter.Fill(ds);
            provider.Conn.Close();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                HoTroTrucTuyen dto = new HoTroTrucTuyen();
                dto.IDHoTro = Convert.ToInt32(ds.Tables[0].Rows[i]["IDHoTro"].ToString());
                dto.TenHienThi = ds.Tables[0].Rows[i]["TenHienThi"].ToString();
                dto.NoiDung = ds.Tables[0].Rows[i]["NoiDung"].ToString();
                dto.PhuongThuc = Convert.ToInt32(ds.Tables[0].Rows[i]["PhuongThuc"].ToString());
                list.Add(dto);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            provider.Conn.Close();
        }
        return list;
    }
}